package annotation;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 简介
 * 作者： 李志伟
 * 日期： 2020/4/22
 * 时间： 17:47
 */
public class AnnotationDemo {


    public static void main(String[] args) {


        Class<AnnotationDemo> clazz = AnnotationDemo.class;

        try {

            Method[] methods = clazz.getMethods();
            for (Method method : methods) {

                if (method.isAnnotationPresent(ADD.class)) {
                    ADD add = method.getAnnotation(ADD.class);
                    Object invoke = method.invoke(clazz.getDeclaredConstructor().newInstance(), add.a(), add.b());
                    System.out.println(invoke == null ? "" : invoke);
                }
            }
        } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | InstantiationException e) {
            e.printStackTrace();
        }
    }

    @ADD(a=5, b=8)
    public void test(int a, int b) {
        System.out.printf("a=%s -- b=%s", a, b);
    }

    @ADD(a=10, b=10)
    public int add(int a, int b) {
        return a + b;
    }

    @Deprecated
    @SuppressWarnings("all")
    public int add2(int a, int b) {
        int c = a + b;
        return c;
    }
}
